package com.ruoyi.ftrl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ftrl.domain.ControlRecords;
import com.ruoyi.ftrl.service.IControlRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 温控阀操控日志Controller
 * 
 * @author dihang
 * @date 2024-08-16
 */
@RestController
@RequestMapping("/ftrl/journal")
public class ControlRecordsController extends BaseController
{
    @Autowired
    private IControlRecordsService controlRecordsService;

    /**
     * 用户查看个人调控记录
     * @param userId
     * @return
     */
    @GetMapping(value = "/controller/{userId}")
    public TableDataInfo getInfoByUser(@PathVariable("userId") Long userId)
    {
//        startPage();
        List<ControlRecords>controlRecords=controlRecordsService.selectControlRecordsByUserId(userId);
        return getDataTable(controlRecords);
    }
    /**
     * 查询温控阀操控日志列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:journal:list')")
    @GetMapping("/list")
    public TableDataInfo list(ControlRecords controlRecords)
    {
        startPage();
        List<ControlRecords> list = controlRecordsService.selectControlRecordsList(controlRecords);
        return getDataTable(list);
    }

    /**
     * 导出温控阀操控日志列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:journal:export')")
    @Log(title = "温控阀操控日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ControlRecords controlRecords)
    {
        List<ControlRecords> list = controlRecordsService.selectControlRecordsList(controlRecords);
        ExcelUtil<ControlRecords> util = new ExcelUtil<ControlRecords>(ControlRecords.class);
        util.exportExcel(response, list, "温控阀操控日志数据");
    }

    /**
     * 获取温控阀操控日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:journal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(controlRecordsService.selectControlRecordsById(id));
    }

    /**
     * 新增温控阀操控日志
     */
    @PreAuthorize("@ss.hasPermi('ftrl:journal:add')")
    @Log(title = "温控阀操控日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ControlRecords controlRecords)
    {
        return toAjax(controlRecordsService.insertControlRecords(controlRecords));
    }

    /**
     * 修改温控阀操控日志
     */
    @PreAuthorize("@ss.hasPermi('ftrl:journal:edit')")
    @Log(title = "温控阀操控日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ControlRecords controlRecords)
    {
        return toAjax(controlRecordsService.updateControlRecords(controlRecords));
    }

    /**
     * 删除温控阀操控日志
     */
    @PreAuthorize("@ss.hasPermi('ftrl:journal:remove')")
    @Log(title = "温控阀操控日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(controlRecordsService.deleteControlRecordsByIds(ids));
    }
}
